﻿@model JaxDug.Models.FeaturedObjects.Book
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Book</legend>
        @if (Model.ISBN != null)
        {
            @Html.HiddenFor(model => model.ISBN)
            <div class="editor-label">
                @Html.ImageLink(Model.CoverImageUrl, Model.Title, Model.AmazonUrl, null, null)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Title)
            </div>
            <div class="editor-field">
                @Html.DisplayFor(model => model.Title)
                @Html.HiddenFor(model => model.Title)
                @Html.ValidationMessageFor(model => model.Title)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Author)
            </div>
            <div class="editor-field">
                @Html.HiddenFor(model => model.Author)
                @Html.DisplayFor(model => model.Author)
                @Html.ValidationMessageFor(model => model.Author)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.Description)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Description)
                @Html.ValidationMessageFor(model => model.Description)
            </div>
            <div class="editor-field">
                @Html.HiddenFor(model => model.AmazonUrl)
                @Html.ValidationMessageFor(model => model.AmazonUrl)
                @Html.HiddenFor(model => model.CoverImageUrl)
                @Html.ValidationMessageFor(model => model.CoverImageUrl)
            </div>
            <p>
                <input type="submit" value="Create" />
            </p>
        }
        else
        {
            <div class="editor-label">
                @Html.LabelFor(model => model.ISBN)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.ISBN)
                @Html.ValidationMessageFor(model => model.ISBN)
            </div>
            <div>
                <label id="FetchBook">
                    Get Book</label>
            </div>

            <script type="text/javascript">

                $('#FetchBook').click(function () {
                    var id = $('#ISBN').val();
                    $.get('/Book/CreateBookForm?id=' + id, function (data) {
                        $('form').replaceWith(data);
                    });
                });

            </script>

        }
    </fieldset>
}